#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <string.h>
#include <semaphore.h>
#include "hfile.h"

#define FILEPATH "/tmp/mmapedupload.bin"
#define NUMINTS  (1000)
#define FILESIZE (NUMINTS * sizeof(int))

int recvFromFsp(int descClient)
{
    int fd;
    char *map;  /* mmapped array of chars(array of chars) */  

    fd = open(FILEPATH, O_RDWR);
    if (fd == -1)
    {
	perror("Error opening file for reading");
	exit(EXIT_FAILURE);
    }

    //Open mmap
    map = mmap(0, FILESIZE, PROT_READ, MAP_SHARED, fd, 0);
    if (map == MAP_FAILED)
    {
	close(fd);
	perror("Error mmapping the file");
	exit(EXIT_FAILURE);
    }

    printf("De Waarde in mmap is %s\n:", map);

    //Send value form mmap to client
    printf("Inhoud desc: %d\n", descClient);    //Debug regel of de client desc goed door komt(is oke)

    if(send(descClient, map,BUFLEN)<1)  //<-------------Moet nog getest worden met client, stuurd data van mmap naar client via send
    {
        perror("fout");
    }

    return 0;
}

